package com.noble.glamour.bean.start;

import android.os.Parcel;
import android.os.Parcelable;

import com.noble.library.base.bean.BaseData;

import org.json.JSONObject;

/**
 * 注册返回结果（手机，微信）
 * Created by Su on 2017/10/14.
 */
public class RegResult extends BaseData implements Parcelable {
    private String mobile;
    private boolean newUser;    // 是否是新用户
    private String cookie;
    private long uid;   // 用户ID
    private String md5Password;  // md5加密password

    @Override
    public void parseJson(String jsonStr) {
        JSONObject object = getJsonObject(jsonStr);

        this.setUid(object.optLong("uid"));
        this.setMd5Password(object.optString("password"));
        this.setMobile(object.optString("mobile"));
        this.setNewUser(object.optBoolean("newuser"));
        this.setCookie(object.optString("token"));
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public boolean isNewUser() {
        return newUser;
    }

    public void setNewUser(boolean newUser) {
        this.newUser = newUser;
    }

    public String getCookie() {
        return cookie;
    }

    public void setCookie(String cookie) {
        this.cookie = cookie;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public RegResult() {
    }

    public String getMd5Password() {
        return md5Password;
    }

    public void setMd5Password(String md5Password) {
        this.md5Password = md5Password;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.mobile);
        dest.writeByte(this.newUser ? (byte) 1 : (byte) 0);
        dest.writeString(this.cookie);
        dest.writeLong(this.uid);
        dest.writeString(this.md5Password);
    }

    protected RegResult(Parcel in) {
        this.mobile = in.readString();
        this.newUser = in.readByte() != 0;
        this.cookie = in.readString();
        this.uid = in.readLong();
        this.md5Password = in.readString();
    }

    public static final Creator<RegResult> CREATOR = new Creator<RegResult>() {
        @Override
        public RegResult createFromParcel(Parcel source) {
            return new RegResult(source);
        }

        @Override
        public RegResult[] newArray(int size) {
            return new RegResult[size];
        }
    };
}
